package com.jay.base.fileIO;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

/**
 * Created by caoyuan7 on 2020/8/13.
 */
public class Person implements Serializable {
    private String name;
    private int age;

    public Person(String name, int age){
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }

    public static void main(String args[]) throws IOException, ClassNotFoundException {
//        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("D:\\json.txt"));
//
//        Person person = new Person("bsg",20);
//        oos.writeObject(person);


        ObjectInputStream ins = new ObjectInputStream(new FileInputStream("D:\\json.txt"));
        Person p = (Person)ins.readObject();
        System.out.println(p.getName());
        System.out.println(p.getAge());
    }
}
